package zym.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import util.Page;
import zym.service.TansferMag;

public class serchLeave extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		int pageNo=1;
		int pageSize=5;
		Page page=null;
		TansferMag tf = new TansferMag();
		try{
			if(request.getParameter("pageNo")!=null)
			{
				pageNo=Integer.parseInt(request.getParameter("pageNo"));
			}
			if(request.getParameter("pageSize")!=null)
			{
				pageSize=Integer.parseInt(request.getParameter("pageSize"));
				request.getSession().setAttribute("pageSize", pageSize);
			}
			if(request.getSession().getAttribute("pageSize")!=null)
			{
				pageSize=(Integer) request.getSession().getAttribute("pageSize");
			}
		}catch(Exception e)
		{
			e.printStackTrace();
		}
		
		
		
		if("lage".equals(request.getParameter("q_type"))){
			int type = Integer.parseInt(request.getParameter("querytype"));
			page=tf.getAllEmpByAge(pageNo, pageSize, type);
		}
		else if("lname".equals(request.getParameter("q_type"))){
			String type=request.getParameter("querytype");
			page=tf.getAllEmpByName(pageNo, pageSize, type);
		}
		else
			page=tf.getLeaveEmp(pageNo, pageSize);
			;
		request.setAttribute("page", page);
		request.getRequestDispatcher("/Transfer/leave.jsp").forward(request, response);
	}

}
